package pkg

import (
	"io"
	"log"
	"net/http"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func OssFile(Filename string) {
	client, err := oss.New("https://oss-cn-shanghai.aliyuncs.com", "LTAI5tA4AcHESS68mHu42Vjm", "zT6vpb1HX24lpWhxV2Vgcz5tHGyA1K")
	if err != nil {
		log.Fatalf("Failed to create OSS client: %v", err)
	}
	// 填写存储空间名称，例如examplebucket。
	bucketName := "2206awangyashuo" // 请替换为实际的Bucket名称
	bucket, err := client.Bucket(bucketName)
	if err != nil {
		log.Fatalf("Failed to get bucket: %v", err)
	}

	// 填写Object的完整路径，例如exampledir/exampleobject.txt。
	objectName := "exampledir/" + Filename

	// 指定待上传的网络流。
	resp, err := http.Get("https://2206awangyashuo.oss-cn-shanghai.aliyuncs.com/exampledir/%E8%81%94%E6%83%B3%E6%88%AA%E5%9B%BE_20240812092428.png" + "?x-oss-process=image/watermark,text_SGVsbG8gV29ybGQ")
	if err != nil {
		log.Fatalf("Failed to fetch URL: %v", err)
	}
	defer resp.Body.Close()

	// 将网络流上传至OSS。
	err = bucket.PutObject(objectName, io.Reader(resp.Body))
	if err != nil {
		log.Fatalf("Failed to put object: %v", err)
	}
	log.Println("File uploaded successfully.")
}
